package com.wolfalpha.utron.activity.base;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;

import com.umeng.analytics.MobclickAgent;
import com.wolfalpha.utron.app.AppManager;
import com.wolfalpha.utron.ui.UIHelper;

/**
 * 基础Activity
 *
 * @author
 * @version 1.0
 * @created 2012-9-18
 */
public class BaseActivity extends Activity {

    private long lastTouchTime = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppManager.getAppManager().addActivity(this);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        AppManager.getAppManager().finishActivity(this);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (System.currentTimeMillis() - lastTouchTime < 2000) {
                //两秒内点击两次退出
                finish();
            } else {
                //提示再点击一次退出
                UIHelper.ToastMessage(this, "再按一次退出");
                lastTouchTime = System.currentTimeMillis();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    public void onResume() {
        super.onResume();
        //友盟统计
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        //友盟统计
        MobclickAgent.onPause(this);
    }
}
